"use strict"
/// <reference path="../../../index.d.ts" />
const Controller = require("egg").Controller
let {sendStat} = require("../../extend/helper")
class Admin extends Controller {
	constructor(ctx) {
		super(ctx)
		this.constant = this.config.constant
		this.serverConfig = this.config.serverConfig
		this.AssistData = this.app.model.Game.AssistData
		this.UserProp = this.app.model.Game.UserProp
		this.UserEmpireStore = this.app.model.Game.UserEmpireStore
		this.GameUser = this.app.model.Game.GameUser
	}

	async	clearUserData() {
		let body = this.ctx.query
		this.ctx.validate({id: "numstr"}, body)
		this.ctx.logger.warn({
			d: new Date(),
			oid: body.id,
			admin: this.ctx.session.adminUser
		})
		let gameUserNum = await this.GameUser.destroy({
			where: {
				oid: body.id
			}
		})
		let assistDataNum = await this.AssistData.destroy({
			where: {
				oid: body.id
			}
		})
		let userPropNum = await this.UserProp.destroy({
			where: {
				oid: body.id
			}
		})
		let gameUserSign = await this.app.model.Game.GameUserSign.destroy({
			where: {
				oid: body.id
			}
		})
		let gameUserTsk = await this.app.model.Game.GameUserTsk.destroy({
			where: {
				oid: body.id
			}
		})

		await this.app.redis.del(this.app.config.redisPrefix.gameUser + body.id)

		let userEmpireStoreNum = await this.UserEmpireStore.destroy({
			where: {
				oid: body.id
			}
		})
		this.ctx.body = sendStat(this.constant.NORMAL, {gameUserNum, assistDataNum, userPropNum, userEmpireStoreNum, gameUserSign, gameUserTsk})
	}
}
module.exports = Admin